from machine import Pin
from board import LED
import socket
# html response
html_response = """
ESP32 LED ON/OFF
MicroPython Web Server
"""
led = Pin(LED, Pin.OUT)
# WebServer
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(3)
while True:
print("Waiting for connection ...")
conn, addr = s.accept()
print("Got a connection from %s" % str(addr))
request = conn.recv(1024)
print("Content = %s" % str(request))
request = str(request)
if 'GET /?LED=ON' in request:
print('Turn led on')
led(1)
if 'GET /?LED=OFF' in request:
print('Turn lef off')
led(0)
conn.send(html_response)
conn.close()